using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;

partial struct SetupUnitMoverDefaultPostionSystem : ISystem
{

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        EntityCommandBuffer EntityCommandBuffer =
            SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>().CreateCommandBuffer(state.WorldUnmanaged);
        foreach ((RefRO<LocalTransform> localTransform, RefRW<UnitMover> unitMover, RefRO<SetupUnitMoverDefaultPostion> setupUnitMoverDefaultPostion, Entity entity) in
            SystemAPI.Query<RefRO<LocalTransform>, RefRW<UnitMover>, RefRO<SetupUnitMoverDefaultPostion>>().WithEntityAccess())
        {
            unitMover.ValueRW.targetPosition = localTransform.ValueRO.Position;
            EntityCommandBuffer.RemoveComponent<SetupUnitMoverDefaultPostion>(entity);
        }
    }

}
